
/**
 * 订阅者
 * @param {Object} vm vue对象
 * @param {String} exp 属性名
 * @param {Function} cb 回调函数
 */
function Watcher(vm, exp, cb) {
  this.vm = vm;
  this.exp = exp;
  this.cb = cb;
  this.value = this.get();
}
 
Watcher.prototype = {
  constructor: Watcher,
  update: function() {
    this.run();
  },
  run: function() {
    var newVal = this.vm.data[this.exp];
    var oldVal = this.value;
    if(newVal != oldVal) {
      this.cb.call(this.vm, newVal, oldVal);
    }
  },
  get: function() {
    Dep.target = this;
    var value = this.vm.data[this.exp];
    Dep.target = null;
    return value;
  }
}